package com.hnmqet.demo02.controller;


import com.hnmqet.demo02.dao.OrderTblMapper;
import com.hnmqet.demo02.entity.OrderTbl;
import com.hnmqet.demo02.service.OrderTblService;
import io.seata.core.context.RootContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author td
 * @since 2020-01-07
 */
@RestController
@RequestMapping
public class OrderTblController {
    @Autowired
    OrderTblService orderTblService;
    @Autowired
    HttpServletRequest request;
    @Autowired
    OrderTblMapper orderTblMapper;

    @RequestMapping("/insert")
    void insert(@RequestParam("userId") String userId, @RequestParam("code") String code, @RequestParam("count") String count) {
        orderTblService.test(userId, code, count);
        // 测试批量添加
/*        List<OrderTbl> list = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            OrderTbl orderTbl = new OrderTbl();
            orderTbl.setUserId("www");
            orderTbl.setCommodityCode("ss");
            orderTbl.setCount(Integer.parseInt("1"));
            list.add(orderTbl);

        }
        long currentTimeMillis = System.currentTimeMillis();
        orderTblService.saveBatch(list);
        //orderTblMapper.insertBatch(list);
        System.err.println(System.currentTimeMillis() - currentTimeMillis);
        String xid = request.getHeader(RootContext.KEY_XID);
        System.err.println(xid);*/
        ;
    }

    @RequestMapping("/batchUpdate")
    void insert() {
        String xid = request.getHeader(RootContext.KEY_XID);
        System.err.println(xid);
        orderTblService.batchUpdate();
    }

    @RequestMapping("/test")
    void insert(String aaa) {
        String xid = request.getHeader(RootContext.KEY_XID);
        System.err.println(xid);
        OrderTbl orderTbl = new OrderTbl();
        orderTbl.setMoney(11);
        orderTbl.setUserId("1");
        orderTblService.save(orderTbl);
    }

}

